targetsystem = {}
function HUDPaint_targets()
	local timeout = 6
	local radius = 10
	local textdistance = 3
	local tick = CurTime() * 90
			-- First Target
	if targetsystem.T1_show == true then
		if targetsystem.T1_updated + timeout < CurTime() or !targetsystem.T1_ent:IsValid() then
			targetsystem.T1_show = false
		else
			
			local TEnt = targetsystem.T1_ent
			local TScreenPos = TEnt:GetPos():ToScreen()
			local TText = targetsystem.T1_txt
			
			for i = 1,3 do
				local ticka = tick + (360/3 * (i-1))
				xa = math.cos(math.rad(ticka)) * radius + TScreenPos.x
				ya = math.sin(math.rad(ticka)) * radius + TScreenPos.y
				local tickb = tick + (360/3 * i)
				xb = math.cos(math.rad(tickb)) * radius + TScreenPos.x
				yb = math.sin(math.rad(tickb)) * radius + TScreenPos.y
				
				surface.SetDrawColor(255,0,0,255)  --green
				surface.DrawLine( xa, ya, xb, yb )
				
				draw.SimpleText( TText, "ScoreboardText", TScreenPos.x, TScreenPos.y - (radius + textdistance), Color(0,255,0,255), 1, 1 )
				
			end
			
		end
	end
	
			-- Second Target
	
	if targetsystem.T2_show == true then
		if targetsystem.T2_updated + timeout < CurTime() or !targetsystem.T2_ent:IsValid() then
			targetsystem.T2_show = false
		else
			
			local TEnt = targetsystem.T2_ent
			local TScreenPos = TEnt:GetPos():ToScreen()
			local TText = targetsystem.T2_txt
			
			for i = 1,3 do
				local ticka = tick + (360/3 * (i-1))
				xa = math.cos(math.rad(ticka)) * radius + TScreenPos.x
				ya = math.sin(math.rad(ticka)) * radius + TScreenPos.y
				local tickb = tick + (360/3 * i)
				xb = math.cos(math.rad(tickb)) * radius + TScreenPos.x
				yb = math.sin(math.rad(tickb)) * radius + TScreenPos.y
				
				surface.SetDrawColor(0,255,0,255)  --green
				surface.DrawLine( xa, ya, xb, yb )
				
				draw.SimpleText( TText, "ScoreboardText", TScreenPos.x, TScreenPos.y - (radius + textdistance), Color(0,255,0,255), 1, 1 )
				
			end
			
		end
	end

	if targetsystem.T3_show == true then
		if targetsystem.T3_updated + timeout < CurTime() or !targetsystem.T3_ent:IsValid() then
			targetsystem.T3_show = false
		else
			
			local TEnt = targetsystem.T3_ent
			local TScreenPos = TEnt:GetPos():ToScreen()
			local TText = targetsystem.T3_txt
			
			for i = 1,3 do
				local ticka = tick + (360/3 * (i-1))
				xa = math.cos(math.rad(ticka)) * radius + TScreenPos.x
				ya = math.sin(math.rad(ticka)) * radius + TScreenPos.y
				local tickb = tick + (360/3 * i)
				xb = math.cos(math.rad(tickb)) * radius + TScreenPos.x
				yb = math.sin(math.rad(tickb)) * radius + TScreenPos.y
				
				surface.SetDrawColor(180,130,0,255)  --reddish color
				surface.DrawLine( xa, ya, xb, yb )
				
				draw.SimpleText( TText, "ScoreboardText", TScreenPos.x, TScreenPos.y - (radius + textdistance), Color(180,130,0,255), 1, 1 )
				
			end
			
		end
	end
	
	
	
end
hook.Add("HUDPaint","targetsystem_HUD",HUDPaint_targets)



function recieve_target_umsg_1( um ) 

	local EID = um:ReadLong()
	local Text = um:ReadString()
	local Ent = ents.GetByIndex(EID)
	
	targetsystem.T1_ent = Ent
	targetsystem.T1_txt = Text
	targetsystem.T1_show = true
	targetsystem.T1_updated = CurTime()

end
usermessage.Hook("Target1", recieve_target_umsg_1) 

function recieve_target_umsg_2( um ) 

	local EID = um:ReadLong()
	local Text = um:ReadString()
	local Ent = ents.GetByIndex(EID)
	
	targetsystem.T2_ent = Ent
	targetsystem.T2_txt = Text
	targetsystem.T2_show = true
	targetsystem.T2_updated = CurTime()

end
usermessage.Hook("Target2", recieve_target_umsg_2) 

function recieve_target_umsg_3( um ) 

	local EID = um:ReadLong()
	local Text = um:ReadString()
	local Ent = ents.GetByIndex(EID)
	
	targetsystem.T3_ent = Ent
	targetsystem.T3_txt = Text
	targetsystem.T3_show = true
	targetsystem.T3_updated = CurTime()

end
usermessage.Hook("Target3", recieve_target_umsg_3) 











